package cn.t.web.order;

import cn.t.core.mode.PageInfoDTO;
import cn.t.core.mode.PageQueryDTO;
import cn.t.dto.order.ReconDetailDTO;
import cn.t.facade.order.ReconDetailFacade;
import cn.t.request.ReconDetailReq;
import cn.t.vo.order.ReconDetailVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 对账管理
 */
@Slf4j
@RestController
@RequestMapping("reconDetail")

@AllArgsConstructor
public class ReconDetailController {

    private final ReconDetailFacade reconDetailFacade;

    /**
     *对账明细分页列表
     */
    @PostMapping("/page")
    public PageInfoDTO<ReconDetailVO> page(@Validated @RequestBody PageQueryDTO<ReconDetailReq> req){
        return this.reconDetailFacade.page(req);
    }

    /**
     * 新增编辑对账单明细
     */
    @PostMapping("/addOrUpdate")
    public Boolean addOrUpdate(@RequestBody ReconDetailDTO req){
        if (ObjectUtils.isEmpty(req.getId())) {
            return this.reconDetailFacade.add(req);
        } else {
            return this.reconDetailFacade.update(req);
        }
    }

    /**
     * 删除对账单明细
     */
    @PostMapping("/remove/{id}")
    public Boolean remove(@PathVariable Long id){
        return this.reconDetailFacade.remove(id);
    }

}

